package com.example.optimizedemo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tangjiangxu on 11/6/17.
 */

public class TestManager {
    private List<OnDataArrivedListener> mOnDataArriedListener = new ArrayList<>();

    private static class SingletonHolder {
        public static final TestManager INSTANCE = new TestManager();
    }

    private TestManager() {

    }

    public static TestManager getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public synchronized  void registerListener(OnDataArrivedListener listener) {
        if (!mOnDataArriedListener.contains(listener)) {
            mOnDataArriedListener.add(listener);
        }
    }

    public synchronized void unregisterListener(OnDataArrivedListener listener) {
        mOnDataArriedListener.remove(listener);
    }


    public interface OnDataArrivedListener {
        public void onDataArrived(Object data);
    }
}
